﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BuildPlannerLib.SimEvents
{
    // Derived class from Event for a worker having travelled far enough to mine a gas geyser
    public class ReachGasGeysers : SimEvent
    {
        // Field for the base at which mining is taking place
        public Base AtBase;

        // Constructor with parameters for parent build, base, and time
        public ReachGasGeysers(Build build, Base b, int time)
        {
            Build = build;
            AtBase = b;
            Time = time;
        }

        // If there is an idle gas geyser, mines from it.  Otherwise, sets the worker to the Idle category.
        public override void Execute()
        {
            AtBase.GasWorkerStatus[0]--;
            int yield = 0;
            int newTime = Time;
            if (AtBase.IdleGasGeysers[2] > 0)
            {
                yield = 8;
                newTime += 211;
                AtBase.IdleGasGeysers[2]--;
                Build.EventList.Add(new FinishGasMining(Build, AtBase, yield, newTime));
            }
            else if (AtBase.IdleGasGeysers[1] > 0)
            {
                yield = 6;
                newTime += 211;
                AtBase.IdleGasGeysers[1]--;
                Build.EventList.Add(new FinishGasMining(Build, AtBase, yield, newTime));
            }
            else if (AtBase.IdleGasGeysers[0] > 0)
            {
                yield = 4;
                newTime += 211;
                AtBase.IdleGasGeysers[0]--;
                Build.EventList.Add(new FinishGasMining(Build, AtBase, yield, newTime));
            }
            else
            {
                AtBase.GasWorkerStatus[1]++;
            }
        }

        public override Base GetBase()
        {
            return AtBase;
        }
    }
}
